/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package technotheist.geo.graph;

import com.jme3.math.Vector3f;

/**
 *
 * @author Mitch
 */
public class GeoTriangle extends GeoNode<GeoTriangle, GeoCell> {
    final int octal;
    final GeoCell v0;
    final GeoCell v1;
    final GeoCell v2;
    final HalfEdge<GeoCell, GeoTriangle> b0;
    final HalfEdge<GeoCell, GeoTriangle> b1;
    final HalfEdge<GeoCell, GeoTriangle> b2;
    private HalfEdge<GeoTriangle, GeoCell> n0;
    private HalfEdge<GeoTriangle, GeoCell> n1;
    private HalfEdge<GeoTriangle, GeoCell> n2;

    public GeoTriangle(GeoCell v0, GeoCell v1, GeoCell v2, final GeoGrid grid) {
        super(new Vector3f().addLocal(v0.pos).addLocal(v1.pos).addLocal(v2.pos).divideLocal(3), grid);
        this.octal = GeoUtil.SolveOctal(pos);
        this.v0 = v0;
        this.v1 = v1;
        this.v2 = v2;
        this.b0 = new HalfEdge(v0, v1, this);
        this.b1 = new HalfEdge(v1, v2, this);
        this.b2 = new HalfEdge(v2, v0, this);
        this.b0.initSymm(grid.triEdges);
        this.b1.initSymm(grid.triEdges);
        this.b2.initSymm(grid.triEdges);
    }

    @Override
    public int ID() {
        return octal;
    }

    @Override
    public int sideCount() {
        return 3;
    }

    @Override
    public HalfEdge<GeoCell, GeoTriangle> getBoundEdge(int i) {
        if (i == 0) {
            return b0;
        }
        if (i == 1) {
            return b1;
        }
        if (i == 2) {
            return b2;
        }
        throw new IllegalArgumentException("Bound index must be between 0, 1 or 2.");
    }

    @Override
    public HalfEdge<GeoTriangle, GeoCell> getNextEdge(int i) {
        if (i == 0) {
            return n0;
        }
        if (i == 1) {
            return n1;
        }
        if (i == 2) {
            return n2;
        }
        throw new IllegalArgumentException("Next index must be between 0, 1 or 2.");
    }
    
}
